package uk.co.accolade.clash.core;

import java.util.List;
import java.util.ArrayList;

public class ClashHandlerRegistry {

    private List<ClashHandler> clashHandlers = new ArrayList<ClashHandler>();

    public void registerClashHandler( ClashHandler clashHandler ) {
        clashHandlers.add( clashHandler );
    }

    public void handleClashes( List<UserChanges> newClashes ) {
        for(UserChanges changes : newClashes) {
            handleClashes( changes );
        }
    }

    public void clearClashes( List<UserChanges> changesToClear ) {
        for(UserChanges changes : changesToClear) {
            clearClashes( changes );
        }
    }

    public void handleClashes( UserChanges changes ) {
        if( changes.hasChanges() ) {
            for( ClashHandler clashHandler : clashHandlers ) {
                clashHandler.handleClashes( changes );
            }
        }
    }

    public void clearClashes( UserChanges changes ) {
        if( changes.hasChanges() ) {
            for( ClashHandler clashHandler : clashHandlers ) {
                clashHandler.clearClashes( changes );
            }
        }
    }
}